<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

  <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('订单编号')}:</label>
    <div class="col-xs-12 col-sm-8">
      <input id="c-order_no" class="form-control" name="row[order_no]" type="text" value="{$row.order_no}" readonly>

      <input id="c-charge_id" style="display: none" class="form-control" name="row[charge_id]" type="text" value="{$row.charge_id}" readonly>
    </div>
  </div>

  <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('分润情况')}:</label>
    <div class="col-xs-12 col-sm-8">
      <input id="c-share" class="form-control" type="text" value="{$row.share}" readonly>
    </div>
  </div>

  <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('充值获得余额')}:</label>
    <div class="col-xs-12 col-sm-8">
      <input id="c-get_amount" class="form-control" name="row[get_amount]" type="text" value="{$row.get_amount}" readonly>
    </div>
  </div>

  <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('用户现有余额')}:</label>
    <div class="col-xs-12 col-sm-8">
      <input id="c-balance" class="form-control" name="row[balance]" type="text" value="{$row.balance}" readonly>
    </div>
  </div>

  <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('退款类型')}:</label>
    <div class="col-xs-12 col-sm-10">
      <div class="radio radio-inline">
        <input type="radio" name="row[type]" id="refundRecharge" value="0" checked>
        <label for="refundRecharge">{:__('退款退充值余额')}</label>
      </div>
      <div class="radio radio-inline">
        <input type="radio" name="row[type]" id="refundClear" value="1">
        <label for="refundClear">{:__('退款清空余额')}</label>
      </div>

      <div class="radio radio-inline">
        <input type="radio" name="row[type]" id="clearBalance" value="2">
        <label for="clearBalance">{:__('仅清空余额')}</label>
      </div>
    </div>
  </div>

  <div class="form-group" id="c-refund_amount">
    <label class="control-label col-xs-12 col-sm-2">{:__('退款金额')}:</label>
    <div class="col-xs-12 col-sm-8">
      <input id="c-refund_amount1" data-required="true" required class="form-control" step="0.01" name="row[refund_amount]" type="number" value="{$row.amount}">
    </div>
  </div>

  <div class="form-group layer-footer">
    <label class="control-label col-xs-12 col-sm-2"></label>
    <div class="col-xs-12 col-sm-8">
      <button type="submit" class="btn btn-primary">{:__('OK')}</button>
      <button type="reset" class="btn btn-default">{:__('Reset')}</button>
    </div>
  </div>
</form>

<script>
  // 等待DOM加载完成
  document.addEventListener('DOMContentLoaded', function() {
    // 获取相关元素
    const clearBalanceRadio = document.getElementById('clearBalance');
    const refundAmountInput = document.getElementById('c-refund_amount');
    const refundRadios = document.querySelectorAll('input[name="row[type]"]');

    // 定义处理函数
    function handleRefundTypeChange() {
      const isClearOnly = clearBalanceRadio.checked;

      if (isClearOnly) {
        // 仅清空余额时隐藏输入框并设值为0
        refundAmountInput.style.display = 'none';
        refundAmountInput.value = '0';
      } else {
        // 其他情况显示输入框
        refundAmountInput.style.display = 'block';
      }
    }

    // 初始加载时执行一次
    handleRefundTypeChange();

    // 为所有单选按钮添加事件监听
    refundRadios.forEach(radio => {
      radio.addEventListener('change', handleRefundTypeChange);
    });
  });

</script>
